<template>
  <div class="contioner">
    <div ref="myChart" :style="{ width: '100%', height: '100%' }"></div>
  </div>
</template>
    
<script lang="ts" setup>
import * as echarts from 'echarts'
import { Message } from '@arco-design/web-vue'
import { ref, reactive, onMounted, watch } from 'vue'
//引入封装post
import { post, get } from '@/api/http'
import dayjs from 'dayjs'
//getlist初始化接口参数
let query: any = reactive({
  beginDate: dayjs().format('YYYY-MM-DD'), //当天日期
  enginDate: dayjs().format('YYYY-MM-DD'),
  // enginDate: formatDateTime(new Date(Number(new Date().getTime()) + (60 * 1000 * 60 * 24 * 7)), 'yyyy-MM-dd'),
  planOrderCode: localStorage.getItem('firmId') || '',
})

const option = ref({
  title: {
    text: '厂辅助工(拆纱卸纱机修)效率',
  },
  tooltip: {
    trigger: 'axis',
  },
  //   legend: {
  //     data: ['拆纱重量/吨', '卸纱重量/吨', '机修台数/台'],
  //   },
  grid: {
    left: '3%',
    right: '3%',
    bottom: '2%',
    containLabel: true,
  },
  xAxis: {
    type: 'category',
    boundaryGap: false,
    data: ['2.1', '2.2', '2.3', '2.4', '2.5', '2.6', '2.7'],
    axisLabel: {
      inside: false,
      textStyle: {
        fontSize: '12',
      },
      padding: [5, 0, 0, -5], //文字左右定位
    },
  },
  yAxis: {
    type: 'value',
    splitNumber: 10,
  },
  series: [
    {
      name: '拆纱重量/吨',
      type: 'line',
      data: [20, 25, 62, 47, 12, 57, 69],
      label: { show: true, position: 'top', distance: 10, formatter: '{c}%', fontSize: 16 },
    },
    {
      name: '卸纱重量/吨',
      type: 'line',
      data: [57, 63, 48, 25, 14, 19, 63],
      label: { show: true, position: 'top', distance: 10, formatter: '{c}%', fontSize: 16 },
    },
    {
      name: '机修台数/台',
      type: 'line',
      data: [20, 34, 62, 24, 18, 64, 47],
      label: { show: true, position: 'top', distance: 10, formatter: '{c}%', fontSize: 16 },
    },
  ],
})

//初始化
onMounted(async () => {
  selectJt()
  // state = states()
  // state.setOption(option.value)
})
let state: any = null
window.addEventListener('resize', updateChartSize)
function updateChartSize() {
  state.resize()
}
const myChart: any = ref()
const states = () => {
  return echarts.init(myChart.value)
}

function selectJt() {
  post({
    url: 'planSingle/report/getAuxiliaryEfficiency',
    data: {
      firmId: query.planOrderCode, //公司ID
      dateStart: query.beginDate,
      dateEnd: query.enginDate,
    },
  }).then((res: any) => {
    if (res.code == 200) {
      option.value.xAxis.data = res.data.map((o: any) => {
        return o.date.split('-')[1] + '/' + o.date.split('-')[2]
      })
      option.value.series[0].data = res.data.map((o: any) => {
        return o.disassemble
      })
      option.value.series[1].data = res.data.map((o: any) => {
        return o.wms
      })
      option.value.series[2].data = res.data.map((o: any) => {
        return o.adjustment
      })
      state = states()
      state.setOption(option.value)
    } else {
      Message.error(res.message)
    }
  })
}
</script>
<script lang="ts">
export default defineComponent({
  name: 'DismantlingMachineRepairEfficiency',
})
</script>
<style scoped>
.contioner {
  width: 100%;
  height: 100%;
  background: #fff;
  padding: 10px;
}

:deep(.ag-cell) {
  border-right: 1px solid #dde2eb;
}

:deep(.ag-header-cell) {
  border-right: 1px solid #dde2eb;
}

:deep(.ag-cell-value) {
  user-select: initial;
  -moz-user-select: text;
  -ms-user-select: text;
  -webkit-user-select: text;
}
</style>
    